## Section 1 of the Online Appendix

library(haven)
library(xtable)
library(PNADcIBGE)
library(survey)

## Clear workspace

rm=list(ls())


##Opening the data:

load("ReplicationData.RData")


##Characteristics of the sample:

## Gender

print_labels(SurveyData$sex)
gender <- table(SurveyData$sex)
prop.table(gender)*100


## Age

mean(SurveyData$age)


## Education

print_labels(SurveyData$P3)
education <- table(SurveyData$P3)
prop.table(education)*100


## Region

print_labels(SurveyData$Regiao)
region <- table(SurveyData$Regiao)
prop.table(region)*100


## Race

print_labels(SurveyData$P16)
race <- table(SurveyData$P16)
prop.table(race)*100


## Social class

print_labels(SurveyData$br_socialclass)
SocialClass <- table(SurveyData$br_socialclass)
prop.table(SocialClass)*100



## Get the data from the IBGE (PNAD, 3rd quarter)

PNAD201803 <- get_pnadc(2018, quarter = 3, interview = NULL, vars = NULL, labels = T, design = T, savedir = tempdir())


## Gender

IBGEgender <- svymean(~V2007, PNAD201803, na.rm = T)
IBGEgender


## Age

IBGEage <- svymean(~V2009, PNAD201803, na.rm = T)
IBGEage


## Education

IBGEeducation <- svymean(~VD3004, PNAD201803, na.rm = T)
IBGEeducation


## Race

IBGErace <- svymean(~V2010, PNAD201803, na.rm = T)
IBGErace


## Region

IBGEregion <- svymean(~UF, PNAD201803, na.rm = T)
IBGEregion

IBGEregion <- as.matrix(IBGEregion)

IBGEnorte <- colSums(as.matrix(IBGEregion[1:7,1]))*100
IBGEnorte

IBGEnordeste <- colSums(as.matrix(IBGEregion[8:16,1]))*100
IBGEnordeste

IBGEsudeste <- colSums(as.matrix(IBGEregion[17:20,1]))*100
IBGEsudeste

IBGEsul <- colSums(as.matrix(IBGEregion[21:23,1]))*100
IBGEsul

IBGECentroeste <- colSums(as.matrix(IBGEregion[24:27,1]))*100
IBGECentroeste


